import { getStorage, setStorage } from '~/composables/storage'

export function persistedstate(context) {
  // 初始化取出来
  const curr = getStorage(context.store.$id)
  context.store.$patch(curr)

  // 监听state变化，存到本地
  context.store.$subscribe((_store, state) => {
    setStorage(_store.storeId, state)
  },
  {
    // 组件卸载依赖还在
    detached: true,
  },
  )
}
